package de.wellenblau.wow3D
{
	import fr.seraf.wow.core.WOWEngine;
	import fr.seraf.wow.primitive.WSphere;
	
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.objects.primitives.Sphere;
	
	public class physicSphere3D extends Sphere implements physicDisplayObject3D
	{
		
		private var _saveX:Number;
		private var _saveZ:Number;
		private var _radius:int;
		private var _circumference:Number;
		private var _physicObject:WSphere;
		
		public function physicSphere3D(x:int,y:int,z:int,radius:int,mat:MaterialObject3D)
		{
			
			super(mat,radius);
			this.x = x;
			this.y = y;
			this.z = z;
			
			_radius = radius;
			_saveX = x;
			_saveZ = z;
			_circumference = 2 * Math.PI * radius;
		}
		
		public function createPhysicObjet(wow:WOWEngine):void{
			_physicObject = new WSphere(this.x,this.y,this.z,_radius,false);
			wow.addParticle(_physicObject);
		}
		
		public function getPhysicObject():Object{
			return _physicObject;
		}
		
		public function syncObjects():void{
			this.x = _physicObject.px;
			this.y = _physicObject.py;
			this.z = _physicObject.pz;
			
			// dX / circumference * 360 = rotationX
			this.rotationX += (_saveX - _physicObject.px) / _circumference * 360;
			this.rotationZ += (_saveZ - _physicObject.pz) / _circumference * 360;
			
			
			//wow3D.tracer.clear();
			//wow3D.tracer.appendLine = ((_saveX - _wow.px) / _circumference * 360).toString();
			
			//save position for rotationcalc
			_saveX = _physicObject.px;
			_saveZ = _physicObject.pz;
		}

	}
}